package edu.ncsu.csc326.coffeemaker;

import edu.ncsu.csc326.coffeemaker.exceptions.RecipeException;
import junit.framework.TestCase;

/*
 * This test unit does not reach 100% branch coverage
 * because it is not possible to set field 'name' to NULL
 */

/*
 * Errors found:
 * 
 */


/**
 * 
 * @author Filipe Betzel
 *
 * Unit tests for Recipe class.
 */


public class RecipeTest extends TestCase {
	
	private CoffeeMaker cm;
	private Recipe R;
	private Recipe R2;

	protected void setUp() throws Exception {
		R = new Recipe();
		
		R2 = new Recipe();
		
		cm = new CoffeeMaker();
		
		super.setUp();
	}
	
	////////////////////////
	//getAmtChocolate()
	////////////////////////
	
	public void testGetAmtChocolate() {
		assertEquals(R.getAmtChocolate(), 0);
	}
	
	////////////////////////
	//setAmtChocolate(String)
	////////////////////////
	public void testSetAmtChocolate() throws RecipeException {
		try {
			R.setAmtChocolate("10");
		} catch (NumberFormatException e) {
			fail("NumberFormatException should not be thrown");
		}
		assertEquals(R.getAmtChocolate(), 10);
	}
	
	public void testSetAmtChocolateBadNumber(){
		try {
			R.setAmtChocolate("AH");
			fail("NumberFormatException should be thrown");
		} catch (Exception e) {
			//success if thrown
		}
	}
	
	public void testSetAmtChocolateNegativeNumber() throws NumberFormatException {
		try {
			R.setAmtChocolate("-1");
			fail("RecipeException should be thrown");
		} catch (RecipeException e) {
			//success if thrown
		}
	}
	
	////////////////////////
	//getAmtCoffee()
	////////////////////////
	
	public void testGetAmtCoffee() {
		assertEquals(R.getAmtCoffee(), 0);
	}
	
	////////////////////////
	//setAmtCoffee(String)
	////////////////////////
	
	public void testSetAmtCoffee() throws RecipeException {
		try {
			R.setAmtCoffee("10");
		} catch (NumberFormatException e) {
			fail("NumberFormatException should not be thrown");
		}
		assertEquals(R.getAmtCoffee(), 10);
	}
	
	public void testSetAmtCoffeeBadNumber(){
		try {
			R.setAmtCoffee("AH");
			fail("NumberFormatException should be thrown");
		} catch (Exception e) {
			//success if thrown
		}
	}
	
	public void testSetAmtCoffeeNegativeNumber() throws NumberFormatException {
		try {
			R.setAmtCoffee("-1");
			fail("RecipeException should be thrown");
		} catch (RecipeException e) {
			//success if thrown
		}
	}
	
	////////////////////////
	//getAmtMilk()
	////////////////////////
	
	public void testGetAmtMilk() {
		assertEquals(R.getAmtMilk(), 0);
	}
	
	////////////////////////
	//setAmtMilk(String)
	////////////////////////
	
	public void testSetAmtMilk() throws RecipeException {
		try {
			R.setAmtMilk("10");
		} catch (NumberFormatException e) {
			fail("NumberFormatException should not be thrown");
		}
		assertEquals(R.getAmtMilk(), 10);
	}
	
	public void testSetAmtMilkBadNumber(){
		try {
			R.setAmtMilk("AH");
			fail("NumberFormatException should be thrown");
		} catch (Exception e) {
			//success if thrown
		}
	}
	
	public void testSetAmtMilkNegativeNumber() throws NumberFormatException {
		try {
			R.setAmtMilk("-1");
			fail("RecipeException should be thrown");
		} catch (RecipeException e) {
			//success if thrown
		}
	}
	
	////////////////////////
	//getAmtSugar()
	////////////////////////
	
	public void testGetAmtSugar() {
		assertEquals(R.getAmtSugar(), 0);
	}
	
	////////////////////////
	//setAmtSugar(String)
	////////////////////////
	
	public void testSetAmtSugar() throws RecipeException {
		try {
			R.setAmtSugar("10");
		} catch (NumberFormatException e) {
			fail("NumberFormatException should not be thrown");
		}
		assertEquals(R.getAmtSugar(), 10);
	}
	
	public void testSetAmtSugarBadNumber(){
		try {
			R.setAmtSugar("AH");
			fail("NumberFormatException should be thrown");
		} catch (Exception e) {
			//success if thrown
		}
	}
	
	public void testSetAmtSugarNegativeNumber() throws NumberFormatException {
		try {
			R.setAmtSugar("-1");
			fail("RecipeException should be thrown");
		} catch (RecipeException e) {
			//success if thrown
		}
	}
	
	////////////////////////
	//getName()
	////////////////////////
	
	public void testGetName() {
		assertEquals(R.getName(), "");
	}
	
	////////////////////////
	//setName(String)
	////////////////////////
	
	public void testSetName() {
		R.setName("Test");
		assertEquals(R.getName(), "Test");
	}
	
	public void testSetNameNull() {
		R.setName(null);
		assertEquals(R.getName(), "");
	}
	
	////////////////////////
	//getPrice()
	////////////////////////
	
	public void testGetPrice() {
		assertEquals(R.getPrice(), 0);
	}
	
	////////////////////////
	//setPrice(String)
	////////////////////////
	
	public void testSetPrice() throws RecipeException {
		try {
			R.setPrice("10");
		} catch (NumberFormatException e) {
			fail("NumberFormatException should not be thrown");
		}
		assertEquals(R.getPrice(), 10);
	}
	
	public void testSetPriceBadNumber(){
		try {
			R.setPrice("AH");
			fail("NumberFormatException should be thrown");
		} catch (Exception e) {
			//success if thrown
		}
	}
	
	public void testSetPriceNegativeNumber() throws NumberFormatException {
		try {
			R.setPrice("-1");
			fail("RecipeException should be thrown");
		} catch (RecipeException e) {
			//success if thrown
		}
	}
	
	////////////////////////
	//toString()
	////////////////////////
	
	public void testToString() {
		assertEquals(R.toString(), "");
	}
	
	public void testSetToString() {
		R.setName("Test");
		assertEquals(R.toString(), "Test");
	}
	
	////////////////////////
	//hashCode()
	////////////////////////
	
	public void testHashCode() {
		R.hashCode();
	}
	
	////////////////////////
	//equals(Object)
	////////////////////////
	
	public void testEqualsThis() {
		assertTrue(R.equals(R));
	}
	
	public void testEqualsNull() {
		assertFalse(R.equals(null));
	}
	
	public void testEqualsClass() {
		assertFalse(R.equals(cm));
	}
	
	public void testEqualsDifName() {
		R2.setName("R2");
		assertFalse(R.equals(R2));
	}
	
	public void testEquals() {
		R.setName("Test");
		R2.setName("Test");
		assertTrue(R.equals(R2));
	}
}